package com.bigknow.appstore.web.base.controller;

import com.bigknow.appstore.web.framework.controller.AbstractRestController;
import com.bigknow.appstore.web.framework.util.AuthenticateUserUtil;
import com.bigknow.appstore.web.base.entity.Permission;
import com.bigknow.appstore.web.base.service.IPermissionService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by TwelveFoldEr on 2016/3/11.
 */
@RestController
@RequestMapping(value = "/base/permission")
public class PermissionController extends AbstractRestController<Permission, IPermissionService> {

    @Override
    protected String getBasePath() {
        return "/base";
    }

    @Override
    protected String getBaseName() {
        return "permission";
    }

    @RequestMapping(value = "/rest/tree", method = RequestMethod.GET)
    public List<Permission> tree() {
        return service.getTree();
    }

    @RequestMapping(value = "/rest/selectedTree/{roleId}", method = RequestMethod.GET)
    public List<Permission> selectedTree(@PathVariable String roleId) {
        return service.getSelectedTreeByRoleId(roleId);
    }

    @RequestMapping(value = "/rest/menuTree", method = RequestMethod.GET)
    public List<Permission> menuTree() {
        return service.getMenuTreeByUserId(AuthenticateUserUtil.getUserId());
    }

}
